<!--
    分部加载功能部分
-->
<script>
export default {
	data() {
		return {
			//加载部分状态记录
			sectionLoad: [true],
			//最大加载序号
			sectionShowMax: 0,
			//当前加载序号
			sectionShow: 0,
			sectionMapping: {},
		};
	},
	computed: {
		sectionList() {
			var list = {};
			for (let i in this.sectionMapping) {
				list[this.sectionMapping[i]] = i;
			}
			return list;
		},
	},
	methods: {
		resetSection() {
			this.$set(this, 'sectionLoad', [true]);
			this.sectionShow = 0;
		},
		sectionIsShow(index) {
			return index === this.sectionShow;
		},
	},
	watch: {
		sectionShow(index) {
			if (!this.sectionLoad[index]) {
				if (index > this.sectionShowMax) {
					this.sectionShowMax = index;
				}
				this.$set(this.sectionLoad, index, true);
			}
			var code = this.sectionList[index];
			if (code) {
				let params = this.$route.params;
				history.replaceState({}, null, `/page/${params.node}/${code}`);
			}
		},
	},
	mounted() {
		if (this.sectionMapping[this.$route.params.tab] !== undefined) {
			this.sectionShow = parseInt(this.sectionMapping[this.$route.params.tab]) || 0;
		}
	},
};
</script>
